﻿<MCard Class="mx-auto" MaxWidth=400>

    <MCardTitle Class="white--text orange darken-4">

        User Directory

        <MSpacer></MSpacer>

        <MButton Color="white" Class="text--primary" Fab Small>
            <MIcon>mdi-plus</MIcon>
        </MButton>

    </MCardTitle>

    <MCardText Class="pt-4">
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quasi nobis a at voluptates culpa optio amet! Inventore deserunt voluptatem maxime a veniam placeat, eos impedit nulla quos? Officiis, aperiam ducimus.
    </MCardText>

    <MDivider></MDivider>

    <MVirtualScroll Items="Items" ItemSize=50 Height=300>
        <ItemContent>

            <MListItem>

                <MListItemAvatar>
                    <MAvatar Color="@context.Color" Size=56 Class="white--text">
                        @context.Initials
                    </MAvatar>
                </MListItemAvatar>

                <MListItemContent>
                    <MListItemTitle>
                        @context.FullName
                    </MListItemTitle>
                </MListItemContent>

                <MListItemAction>
                    <MButton Depressed Small>

                        View User

                        <MIcon Color="orange darken-4" Right>
                            mdi-open-in-new
                        </MIcon>
                    </MButton>
                </MListItemAction>

            </MListItem>

        </ItemContent>
    </MVirtualScroll>

</MCard>

@code
{
    string[] _colors = new[] { "#2196F3", "#90CAF9", "#64B5F6", "#42A5F5", "#1E88E5", "#1976D2", "#1565C0", "#0D47A1", "#82B1FF", "#448AFF", "#2979FF", "#2962FF" };

    string[] _names = new[] { "Oliver", "Jake", "Noah", "James", "Jack", "Connor", "Liam", "John", "Harry", "Callum", "Mason", "Robert", "Jacob", "Jacob", "Jacob", "Michael", "Charlie", "Kyle", "William", "William", "Thomas", "Joe", "Ethan", "David", "George", "Reece", "Michael", "Richard", "Oscar", "Rhys", "Alexander", "Joseph", "James", "Charlie", "James", "Charles", "William", "Damian", "Daniel", "Thomas", "Amelia", "Margaret", "Emma", "Mary", "Olivia", "Samantha", "Olivia", "Patricia", "Isla", "Bethany" };

    string[] _surnames = new[] { "Smith", "Anderson", "Clark", "Wright", "Mitchell", "Johnson", "Thomas", "Rodriguez", "Lopez", "Perez", "Williams", "Jackson", "Lewis", "Hill", "Roberts", "Jones", "White", "Lee", "Scott", "Turner", "Brown", "Harris", "Walker", "Green", "Phillips", "Davis", "Martin", "Hall", "Adams", "Campbell", "Miller", "Thompson", "Allen", "Baker", "Parker", "Wilson", "Garcia", "Young", "Gonzalez", "Evans", "Moore", "Martinez", "Hernandez", "Nelson", "Edwards", "Taylor", "Robinson", "King", "Carter", "Collins" };

    Item[] Items
    {
        get
        {
            int namesLength = _names.Length;
            int surnamesLength = _surnames.Length;
            int colorsLength = _colors.Length;

            Item[] items = new Item[10000];
            for (var i = 0; i < 10000; i++)
            {
                string name = _names[GenRandomIndex(namesLength)];
                string surname = _surnames[GenRandomIndex(surnamesLength)];

                items[i] = new Item
                {
                    Color = _colors[GenRandomIndex(colorsLength)],
                    FullName = $"{name} {surname}",
                    Initials = $"{name[0]} {surname[0]}"
                };
            }

            return items;
        }
    }

    public int GenRandomIndex(int length)
    {
        Random r = new Random();

        return (int)Math.Ceiling(r.NextDouble() * (length - 1));
    }

    class Item
    {
        public string Color { get; set; }
        public string FullName { get; set; }
        public string Initials { get; set; }
    }
}